version 14.0
clear all
capture log close
set matsize 500
set more off, perm


*****************************************************************************************
*****************************************************************************************

*****EEOC: RACE-BASED EMPLOYMENT DISCRIMINATION*****
gen ec_race=(dis_race/totalsize)*100
label variable ec_race "RACE-BASED EMPLOYMENT DISCRIMINATION"
gen lg_ecrace=L.ec_race
label variable lg_ecrace "RACE-BASED EMPLOYMENT DISCRIMINATION(LAGGED)"

*****FEVS: AFFECTIVE COMMITMENT CLIMATE*****
label variable afcom "AFFECTIVE COMMITMENT CLIMATE"
gen lg_afcom=L.afcom
label variable lg_afcom "AFFECTIVE COMMITMENT CLIMATE(LAGGED)"

*****FEVS: ETHICAL LEADERSHIP*****
label variable ethics1 "ETHICAL LEADERSHIP-ORG LEVEL"

*****FEVS: DIVERSITY MANAGEMENT*****
label variable divmgt "DIVERSITY MANAGEMENT-ORG LEVEL"

*****FEVS: WHISTLE-BLOWING ATTITUDES*****
rename Q17 whistle
label variable whistle "WHISTLE-BLOWING ATTITUDES-ORG LEVEL"

*****FEVS: FAIR EVALUATION FOR PERFORMANCE*****
rename Q15 fair
label variable fair "FAIR EVALUATION FOR PERFORMANCE-ORG LEVEL"

*****EHRISDM: RACIAL DIVERSITY*****
gen to_race2=indian+asian+black+hawai+hispanic+white
gen p3_indian=(indian/to_race2)^2
gen p3_asian=((asian+hawai)/to_race2)^2
gen p3_black=(black/to_race2)^2
gen p3_hispanic=(hispanic/to_race2)^2
gen p3_white=(white/to_race2)^2
gen ag_race3=p3_indian+p3_asian+p3_black+p3_hispanic+p3_white
gen racediv=1-ag_race3
label variable racediv "RACIAL DIVERSITY, BLAU INDEX"

*****EHRISDM: RACIAL REPRESENTATION OF MANAGMEENT*****
***************************MINORITY MANAGEMENT REPRESENTATIVENESS*****************
gen minper=((indian+asian+black+hawai+morethan1+hispanic)/totalsize)*100
gen obfmin=(((aian13+aian14+asian15+asian13+asian14+asian15+black13+black14+black15+hawai13+hawai14+hawai15+more13+more14+more15+hispa13+hispa14+hispa15)/(aian13+aian14+asian15+asian13+asian14+asian15+black13+black14+black15+hawai13+hawai14+hawai15+more13+more14+more15+hispa13+hispa14+hispa15+white13+white14+white15))*100)-minper
label variable obfmin "MINORITY REPRESENTATIVENESS"

*****EHRISDM: WORKFORCE SIZE(LOG)*****
gen ln_size=ln(totalsize)
label variable ln_size "EHRISDM: WORKFORCE SIZE(LOG)"


*****AGENCY DUMMY*****
gen agency_id=.
replace agency_id=1 if 2<=subelem & subelem<=13
replace agency_id=2 if 14<=subelem & subelem<=16
replace agency_id=2 if subelem==17
replace agency_id=3 if 18<=subelem & subelem<=22
replace agency_id=3 if 24<=subelem & subelem<=26
replace agency_id=4 if 27<=subelem & subelem<=34
replace agency_id=5 if 35<=subelem & subelem<=40
replace agency_id=6 if 41<=subelem & subelem<=48
replace agency_id=7 if 49<=subelem & subelem<=55
replace agency_id=8 if 56<=subelem & subelem<=63
replace agency_id=9 if 64<=subelem & subelem<=66
replace agency_id=9 if 68<=subelem & subelem<=72
replace agency_id=10 if 73<=subelem & subelem<=74
replace agency_id=11 if 76<=subelem & subelem<=80
replace agency_id=11 if 82<=subelem & subelem<=84
replace agency_id=12 if 85<=subelem & subelem<=87

label variable agency_id "AGENCY ID"

*****RELOCATING STUDY VARIABLES*****
order agency_id, before(subelem)
order ec_race lg_ecrace afcom lg_afcom ethics1 divmgt whistle fair racediv obfmin ln_size, after(subelem)

********************************************************************************
*****************************ANALYSIS*******************************************
********************************************************************************

*****AUTOCORRELATIONS*****
xtserial afcom racediv ethics1 lg_afcom divmgt whistle fair obfmin ln_size 
xtserial ec_race racediv ethics1 lg_ecrace divmgt whistle fair obfmin ln_size 

*****HETEROSKEDASTICITY*****
reg afcom racediv ethics1 lg_afcom divmgt whistle fair obfmin ln_size 
hettest
reg ec_race racediv ethics1 lg_ecrace divmgt whistle fair obfmin ln_size 
hettest


*****MODELS M4~M6: DV=RACE-BASED EMPLOYMENT DISCRIMINATION*****
*Model 6*
xi: xtgls ec_race racediv ethics1 c.ethics1##c.racediv lg_ecrace divmgt whistle fair obfmin ln_size i.agency_id i.year , corr(ar1) panel(hetero) force
gen sample=e(sample)

*Model 5*
xi: xtgls ec_race racediv ethics1 lg_ecrace divmgt whistle fair obfmin ln_size i.agency_id  i.year if sample==1 , corr(ar1) panel(hetero) force


*Model 4*
xi: xtgls ec_race lg_ecrace divmgt whistle fair obfmin ln_size i.agency_id i.year if sample==1 , corr(ar1) panel(hetero) force

*****VISUAALIZATION OF MODERATING EFFECT: RACIAL DIVERSITY X ETHICAL LEADERSHIP --> RACE-BASED EMPLOYMENT DISCRIMINATION*****
su ethics1 if sample==1
global Hethics1=r(mean)+r(sd)
global Methics1=r(mean)
global Lethics1=r(mean)-r(sd)

margins, at(racediv=(0.1(0.1)0.7) ethics1=($Hethics1 $Methics1 $Lethics1)) vsquish
marginsplot, recast(line) noci  addplot(afcom ethics1, msym(oh) jitter(3))


*****MODELS M1~M3: DV=AFFECTIVE COMMITMENT CLIMATE*****

*Model 1*
xi: xtgls afcom  lg_afcom divmgt whistle fair obfmin ln_size i.agency_id  i.year if sample==1, corr(ar1) panel(hetero) force

*Model 2*
xi: xtgls afcom  racediv ethics1 lg_afcom divmgt whistle fair obfmin ln_size i.agency_id  i.year if sample==1, corr(ar1) panel(hetero) force

*Model 3*
xi: xtgls afcom  racediv ethics1 c.ethics1##c.racediv lg_afcom divmgt whistle fair obfmin ln_size i.agency_id i.year if sample==1, corr(ar1) panel(hetero) force

*****VISUAALIZATION OF MODERATING EFFECT: RACIAL DIVERSITY X ETHICAL LEADERSHIP --> AFFECTIVE COMMITMENT CLIMATE*****
margins, at(racediv=(0.1(0.1)0.7) ethics1=($Hethics1 $Methics1 $Lethics1)) vsquish
marginsplot, recast(line) noci addplot(ec_race ethics1, msym(oh) jitter(3))


*****DESCRIPTIVE STATS AND CORRELATIONS*****
su afcom  ec_race racediv ethics1 divmgt whistle fair obfmin ln_size if sample==1
pwcorr afcom  ec_race racediv ethics1 divmgt whistle fair obfmin ln_size if sample==1,sig


